/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.Domain;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.Collections;
/*    */ import java.util.HashMap;
/*    */ import java.util.HashSet;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class DeleteGalSyncAccount
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public boolean domainAuthSufficient(Map<String, Object> context)
/*    */   {
/* 41 */     return true;
/*    */   }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*    */   {
/* 46 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 47 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 49 */     Element acctElem = request.getElement("account");
/* 50 */     String acctKey = acctElem.getAttribute("by");
/* 51 */     String acctValue = acctElem.getText();
/*    */     
/* 53 */     Account account = prov.get(Key.AccountBy.fromString(acctKey), acctValue);
/* 54 */     if (account == null) {
/* 55 */       throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
/*    */     }
/* 57 */     checkAccountRight(zsc, account, Rights.Admin.R_deleteAccount);
/*    */     
/* 59 */     String id = account.getId();
/* 60 */     HashSet<String> acctIds = new HashSet();
/* 61 */     Domain domain = prov.getDomain(account);
/* 62 */     Collections.addAll(acctIds, domain.getGalAccountId());
/* 63 */     if (!acctIds.contains(id))
/* 64 */       throw AccountServiceException.NO_SUCH_ACCOUNT(id);
/* 65 */     acctIds.remove(id);
/* 66 */     HashMap<String, Object> attrs = new HashMap();
/* 67 */     attrs.put("zimbraGalAccountId", acctIds);
/* 68 */     prov.modifyAttrs(domain, attrs);
/* 69 */     prov.deleteAccount(id);
/*    */     
/* 71 */     ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "DeleteGalSyncAccount", "id", id }));
/*    */     
/*    */ 
/* 74 */     Element response = zsc.createElement(AdminConstants.DELETE_GAL_SYNC_ACCOUNT_RESPONSE);
/* 75 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 80 */     relatedRights.add(Rights.Admin.R_deleteAccount);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/DeleteGalSyncAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */